
//
//  GraphViewController.m
//  iRMAP
//
//  Created by Ryan Enguero on 4/2/14.
//  Copyright (c) 2014 engueroryan. All rights reserved.
//

#import "GraphViewController.h"
#import "GraphDynamicViewController.h"
#import "CPDScatterPlotViewController.h"
@interface GraphViewController ()

@end
int test = 1;
int DropDownState = 0;
@implementation GraphViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0.0/255.0 green:30.0/255.0 blue:66.0/255.0 alpha:1.0], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
        [self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:0.0/255.0 green:30.0/255.0 blue:66.0/255.0 alpha:1.0]];
    }
    
    
    
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    [self.tabBarController.tabBar setHidden:YES];
    
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0/255.0 green:30.0/255.0 blue:66.0/255.0 alpha:1.0];

    
    
    self.lblFromDate.layer.cornerRadius = 6;
    self.lblSensorDate.layer.cornerRadius = 6;
    self.lblToDate.layer.cornerRadius = 6;
    
    self.btnCancelProp.layer.cornerRadius = 6;
    self.btnDoneProp.layer.cornerRadius = 6;
    
  
    
    [UIView animateWithDuration:2.0 animations:^{
        [self.imgHider setFrame:CGRectMake(320, self.imgHider.frame.origin.y, 0, self.imgHider.frame.size.height)];
    }completion:^(BOOL finished){
        
    }];
    
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)btnFromDropDown:(id)sender {
    [self animationToolBar];
    DropDownState = 1;
    NSLog(@"State %i",DropDownState);
}

- (IBAction)btnSensorDropDown:(id)sender {
    [self animationToolBar];
    DropDownState = 2;
    NSLog(@"State %i",DropDownState);
    
}

- (IBAction)btnToDropDown:(id)sender {
    
    [self animationToolBar];
    
    DropDownState = 3;
    NSLog(@"State %i",DropDownState);
}


- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
//    if(orientationToLandscape)
//    {
//        //when we manually changed, show in Portrait
//        return UIInterfaceOrientationLandscapeRight;
//    }
//    else
//    {
        //before manual orientation change, we allow any orientation
        return UIInterfaceOrientationLandscapeRight;
  //  }
}

//-(BOOL) shouldAutorotate
//{
//    //we should 'lock' the rotation once we manually change it
//    return NO;
//}

- (IBAction)testBtn:(id)sender {
    
    CPDScatterPlotViewController *sg = [[CPDScatterPlotViewController alloc]initWithNibName:@"CPDScatterPlotViewController" bundle:nil];
    
   // [self.navigationController pushViewController:sg animated:YES];
    

    orientationToLandscape = YES;
    
    [self presentViewController:sg animated:NO completion:nil];
}




- (IBAction)btnCancel:(id)sender {
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.ViewToolBar setFrame:CGRectMake(0, 568, 320, 221)];
        [self.ViewToolBar setAlpha:0.0];
    }completion:^(BOOL finished){
        [self.ViewToolBar removeFromSuperview];
        test = 1;
    }];
}

- (IBAction)btnDone:(id)sender {
    
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.ViewToolBar setFrame:CGRectMake(0, 568, 320, 221)];
            [self.ViewToolBar setAlpha:0.0];
        }completion:^(BOOL finished){
            [self.ViewToolBar removeFromSuperview];
            
            NSDateFormatter *formatDay = [[NSDateFormatter alloc]init];
            [formatDay setDateFormat:@"MMM dd yyyy"];
            NSString *day = [formatDay stringFromDate:self.pkDate.date];
            
            if (DropDownState == 1) {
                
                self.lblFromDate.text = day;
                
            }else if (DropDownState == 2){
                
                self.lblSensorDate.text = day;
                
            }else if (DropDownState == 3){
                
                self.lblToDate.text = day;
            }
            
            test = 1;
        }];
    
    
    
}






-(void)animationToolBar{
    if (test == 1) {
        
        [self.ViewToolBar setFrame:CGRectMake(0, 568, 320, 221)];
        [self.view addSubview:self.ViewToolBar];
        [self.ViewToolBar setAlpha:0.0];
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.ViewToolBar setFrame:CGRectMake(0, 300, 320, 221)];
            [self.ViewToolBar setAlpha:1.0];
        }completion:^(BOOL finished){
            
            
            test = 2;
        }];
        
        //NSLog(@"test %i",test);
        
    }else if (test == 2){
        
        [self.ViewToolBar setFrame:CGRectMake(0, 300, 320, 221)];
        [self.ViewToolBar setAlpha:1.0];
        
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.ViewToolBar setFrame:CGRectMake(0, 568, 320, 221)];
            [self.ViewToolBar setAlpha:0.0];
        }completion:^(BOOL finished){
            [self.ViewToolBar removeFromSuperview];
            test = 1;
        }];
        
        //NSLog(@"test %i",test);
    }

}


@end
